import random
from io import BytesIO

from util.myrediss import r


def random_code(key=4):
    str_a_z = [chr(num) for num in range(97,122)]
    str_A_Z = [chr(num) for num in range(65,90)]
    num_0_9=[str(num) for num in range(0,10)]
    a = ''.join(random.sample(str_a_z+str_A_Z+num_0_9, key))
    return a
from captcha.image import ImageCaptcha
def make_verify_image(code_str,image_uuid=None):
    image = ImageCaptcha().generate_image(code_str)
    out = BytesIO()
    image.save(out, 'jpeg')
    return out.getvalue()